package com.lxd.filter.Impl;

import com.lxd.common.constants.CacheConstant;
import com.lxd.common.model.StandardSubmit;
import com.lxd.feign.cacheClient;
import com.lxd.filter.CheckFilter;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Author Dongdong
 * @注释
 */
@Service(value = "transfer")
@Slf4j
public class TransferStrategyFilter implements CheckFilter {
    @Autowired
    private cacheClient client;
    @Override
    public void check(StandardSubmit submit) {
        //1.获取手机号
        String mobile = submit.getMobile();
        //2.从redis中查询是否需要转网
        String is_Transfer = client.getString(CacheConstant.TRANSFER + mobile);

        //3.如果能查出来有值，说明该手机号需要转网
        if (!StringUtils.isEmpty(is_Transfer)){
            Integer operatorId = Integer.valueOf(is_Transfer);
            submit.setOperatorId(operatorId);//设置手机号的 转网后的运营商
            submit.setTransfer(true);//设置该手机号 需要转网
            log.info("【策略模块-携号转网策略】   当前手机号携号转网了！");
            return;
        }

        log.info("【策略模块-携号转网策略】  不需要转网");
    }
}
